package com.njbdqn.mybuy.dao;

import java.util.List;

import org.njbdqn.mybuy.database.SqlTemplate;

import com.njbdqn.mybuy.entity.Shops;

public class ShopsDAO {
	private SqlTemplate template;
	public ShopsDAO(){
		template = new SqlTemplate();
	}
	
	public List<Shops> findAll(){
		String sql="select * from shops";
		return template.resultToArray(sql, new Object[]{}, Shops.class);
	}
	
	public Shops findById(int shopid){
		String sql="select * from shops where shopid=?";
		return (Shops) template.resultToArray(sql, new Object[]{shopid}, Shops.class).get(0);
	}
	
	public List<Shops> findBatchShop(Object [] ids){
		String sql="select * from shops where shopid in (";
		for (int i = 0; i < ids.length; i++) {
			sql+="?,";
		}
		sql.replaceFirst("\\,$", ")");
		return template.resultToArray(sql, ids, Shops.class);
	}
}
